package com.zhang.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
// 这个注解的作用是把AliPayConfigProperties这个类注入到容器中，这样就可以直接在其他地方通过@Resource注解注入到类中
@EnableConfigurationProperties(AliPayConfigProperties.class)
//或者直接使用resource看看行不行，或者直接用；
public class AliPayConfig {

    //todo  还可以实验一下看能不能直接拿到再容器中的AliPayConfigProperties
//    @Resource
//    private AliPayConfigProperties aliPayConfigProperties;

    @Bean("alipayClient")
    public AlipayClient alipayClient(AliPayConfigProperties properties) {
        return new DefaultAlipayClient(properties.getGatewayUrl(),
                properties.getApp_id(),
                properties.getMerchant_private_key(),
                properties.getFormat(),
                properties.getCharset(),
                properties.getAlipay_public_key(),
                properties.getSign_type());
    }

}
